app.controller("specificationController",function (
    $scope,
    specificationService,
    $controller) {
    $scope.list = [];
    $scope.searchEntity = {};
    $scope.entity = {spec:{},specOptionList:[]};

    $controller("baseController",{$scope:$scope});

    $scope.search = function (page,rows) {
        specificationService.findPage(page,rows,$scope.searchEntity).then(function (result) {
            $scope.list = result.data.rows;
            $scope.pageModel.totalItems = result.data.total;
        })
    }
    //添加一行
    $scope.addOption = function () {
        $scope.entity.specOptionList.push({});
    }
    $scope.delOption = function ($index) {
        $scope.entity.specOptionList.splice($index,1);
    }
    $scope.save = function () {
        if ($scope.entity.spec.id){
            specificationService.update($scope.entity).then(function (result) {
                if (result.data.success){
                    $scope.reloadList();
                }else{
                    alert(result.data.message);
                }
            });
        }else{
            specificationService.save($scope.entity).then(function (result) {
                if (result.data.success){
                    $scope.reloadList();
                }else{
                    alert(result.data.message);
                }
            });
        }
    }

    $scope.edit = function (id) {
        specificationService.findOne(id).then(function (result) {
            $scope.entity=result.data;
        })
    }

    $scope.dele = function () {
        specificationService.dele($scope.selectedIds).then(function (result) {
            if (result.data.success){
                $scope.reloadList();
            }else{
                alert(result.data.message);
            }
        })
    }







});